package hy.controller;

import hy.bean.User;
import hy.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;

import javax.servlet.http.HttpSession;

@Controller
public class UserCtrl {
    @Autowired
    UserMapper dao;

    @PostMapping("/login")
    public String login(User u, HttpSession session){
        String p=dao.selectPassByName(u.getName());
        System.out.println("正确密码："+p);
        if(p!=null&&p.equals(u.getPass())){
            session.setAttribute("user",u.getName());
            return "redirect:/showEmps";
        }else{
            session.setAttribute("msg","用户名或密码错误");
            return "redirect:/showLogin";
        }
    }
}
